/**
 *
 * @description:
 * @author:junyong.hong
 * @createTime:2018/1/6
 * @version:1.0.0.0
 * @history:
 *    1、
 *    2、
 *
 */

define([
    'app'
],function (app) {
    'use strict';
    app.factory('qsHttpFactory',['$http',function ($http) {
        var obj = {
            objData:{webs:[],single:[]},

            /**
             * 获取所有数据
             */
            all:function () {
                return $http({url:"js/factory/qsHttpFactory/test.json"}).then(function (response) {
                    obj.objData.webs = response.data;
                    return obj.objData;
                });
            },
            /**
             * 获取一条数据
             * @returns {*}
             */
            find:function (id) {
                return this.all().then(function (data) {

                    for (var i = 0; i < data.webs.length; i++) {
                        if (data.webs[i].id == id) {
                            obj.objData.single = data.webs[i];
                            return obj.objData;
                        }
                    }
                });
            },
            /**
             * 删除所有数据
             */
            flush:function () {
                obj.objData.webs = [];
                obj.objData.single = [];

            }
        };

        return obj;
    }]);
});



